package com.ror.java.se.stream;

/*
    需求：
    集合中存储一些字符串的数据，比如：张三，23。
    收集到Student类型的数组当中
 */

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;

public class Demo05 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list, "张无忌,15", "周芷若,14", "赵敏,13", "张强,20",
                "张三丰,100", "张翠山,40", "张良,35", "王二麻子,37");
        Person[] persons = list.stream().map(Person::new).toArray(Person[]::new);
        System.out.println(Arrays.toString(persons));
    }

    static class Person {
        String name;
        int age;

        Person(String name, int age) {
            this.name = name;
            this.age = age;
        }

        Person(String pattern) {
            this(pattern.split(",")[0], Integer.parseInt(pattern.split(",")[1]));
        }

        public String toString() {
            return "Person{name = " + name + ", age = " + age + "}";
        }
    }

}
